<!DOCTYPE html>
<html>

<head>
    <title>
        <?php echo isset($SyscnfUcenterinfo) && $SyscnfUcenterinfo && $SyscnfUcenterinfo['logintitle'] ? $SyscnfUcenterinfo['logintitle'] : '用户登录' ?>
    </title>

    <meta name="keywords" content="" />

    <meta name="description" content="" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="/static/uc/css/theme.css" rel="stylesheet">
    <link href="/static/uc/lib/layui/css/layui.css" rel="stylesheet">
    <link href="/static/uc/css/login.css" rel="stylesheet">
    <style>
        <?php
        if (isset($SyscnfUcenterinfo) && $SyscnfUcenterinfo && $SyscnfUcenterinfo['welcomepic']) {
        ?>.xcpic {
            background-image: url('<?php echo $SyscnfUcenterinfo['welcomepic'] ?>');
        }

        <?php
        }
        ?>
    </style>
</head>

<body>
    <div class="loginbox">
        <div class="loginform">
            <h2> <?php echo isset($SyscnfUcenterinfo) && $SyscnfUcenterinfo && $SyscnfUcenterinfo['logintitle'] ? $SyscnfUcenterinfo['logintitle'] : '用户登录' ?></h2>
            <div style="padding-top: 10px;">
                <input type="hidden" value="<?php echo $config['captchatype'] ?>" id="captchatype" />
                <?php
                $logregtypes = explode(',', $config['logregtype']);
                ?>
                <form class="layui-form" lay-filter="login-form">
                    <div class="layui-tab layui-tab-brief">
                        <ul class="layui-tab-title">
                            <?php
                            if (in_array(1, $logregtypes)) {
                            ?>
                                <li class="layui-this">账号登录</li>
                            <?php
                            }
                            ?>
                            <?php
                            if (in_array(2, $logregtypes)) {
                            ?>
                                <li class="<?php echo count($logregtypes) == 1 ? 'layui-this' : '' ?>">手机免密登录</li>
                            <?php
                            }
                            ?>
                        </ul>

                        <div class="layui-tab-content">

                            <?php
                            if (in_array(1, $logregtypes)) {
                            ?>
                                <div class="layui-tab-item layui-show rc-pagepadding" submit_logregtype="1">

                                    <input type="hidden" name="logintype" value="1" />
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">账号：</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="username" id="username" placeholder="请输入" autocomplete="off" class="layui-input">
                                        </div>

                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">密码：</label>
                                        <div class="layui-input-block">
                                            <input type="password" name="pwd" id="pwd" placeholder="请输入" autocomplete="off" class="layui-input">
                                        </div>

                                    </div>
                                </div>

                            <?php
                            }
                            ?>
                            <?php
                            if (in_array(2, $logregtypes)) {
                            ?>
                                <div submit_logregtype="2" class="layui-tab-item  rc-pagepadding  <?php echo count($logregtypes) == 1 ? 'layui-show' : '' ?>">

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">手机：</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="phone" id="phone" placeholder="请输入" autocomplete="off" class="layui-input">
                                        </div>

                                    </div>
                                </div>
                            <?php
                            }
                            ?>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <div class="layui-inline" style="position: relative;margin-right:0">
                            <?php
                            if ($config['captchatype'] == 1) {
                            ?>
                                <div class="captchbox" id="captchbox">

                                    <div class="" style="padding: 0!important;">
                                        <img src="" id="captchaimg" class="captchaimg" width="289" height="60" />
                                    </div>
                                </div>
                            <?php
                            } else {
                            ?>
                                <div class="captchbox" id="captchbox">
                                    <div class="layui-input-inline layui-input-wrap" style="width: 162px;">
                                        <input id="captcha" type="text" name="captcha" autocomplete="off" placeholder="请输入验证码" lay-reqtext="" lay-affix="clear" class="layui-input " />
                                    </div>
                                    <div class="layui-form-mid " style="padding: 0!important; width:150px">
                                        <img src="" id="captchaimg" class="captchaimg" width="150" height="40" />
                                    </div>
                                    <div class="layui-form-mid " style="padding: 0!important;margin-right:0!important">
                                        <button type="button" class="layui-btn layui-btn-primary" id="sendsms">发送</button>
                                    </div>
                                </div>
                            <?php
                            }
                            ?>


                            <label class="layui-form-label">验证码：</label>
                            <div class="layui-input-inline layui-input-wrap" style="width: 202px;">
                                <input type="text" id="realcaptcha" name="realcaptcha" lay-verify="required" autocomplete="off" lay-reqtext="请填写短信验证" lay-affix="clear" class="layui-input " />
                            </div>

                            <div class="layui-form-mid " style="padding: 0!important;margin-right:0!important">
                                <button type="button" class="layui-btn " id="showcaptch">获取验证码</button>
                            </div>

                        </div>
                    </div>


                    <div class="layui-form-item">
                        <div style="display: flex; justify-content: space-between;">
                            <div class="layui-form-label"><a href="/uc/Logreg/forgetpwd">忘记密码？</a></div>

                            <div> <a href="/uc/Logreg/register">账号注册</a></div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn layui-btn-primary" lay-submit lay-filter="login_submit">登录</button>
                        </div>

                    </div>
                </form>


            </div>
            <hr>
            <div class="copyright">
                <p> © <?php echo date('Y') ?> FrameCoder集约化管理平台 . All rights 流浪码农 </p>
            </div>
        </div>
        <div class="xcpic">

        </div>
    </div>
    <script src="/static/uc/lib/jquery/jquery.min.js"></script>
    <script src="/static/uc/lib/layui/layui.js"></script>
    <script src="/static/uc/lib/toastr/toastr.min.js"></script>
    <link href="/static/uc/lib/toastr/toastr.min.css" rel="stylesheet">
    <script src="/static/uc/js/rovecoder.js"></script>
    <script>
        layui.use(function() {
            var $ = layui.jquery;
            var layer = layui.layer;
            var form = layui.form;
            var element = layui.element;


            $('#captchaimg').click(function() {
                $('#captchaimg').attr('src', '/uc/Logreg/captcha?width=' + $('#captchaimg').attr('width') + '&height=' + $('#captchaimg').attr('height') + '&t=' + Math.random());
            });

            $('#showcaptch').click(function() {
                var submit_logregtype = $('.layui-show').attr('submit_logregtype');

                if (submit_logregtype == 1 && $('#username').val() == '') {
                    toastr_error('请填写账户');
                    return;
                }

                if (submit_logregtype == 2 && $('#phone').val() == '') {
                    toastr_error('请填写手机号');
                    return;
                }

                if (!$('#captchbox').is(":visible")) {
                    $('#captchaimg').attr('src', '/uc/Logreg/captcha?width=' + $('#captchaimg').attr('width') + '&height=' + $('#captchaimg').attr('height') + '&t=' + Math.random());
                    $('#captchbox').show();
                }
            });

            $(document).click(function(event) {
                var event = event.srcElement ? event.srcElement : event.target;

                if (event.id != 'showcaptch' && event.id != 'captcha' && event.id != 'captchaimg' && event.id != 'sendsms' && event.id != 'captchbox' && event.id != 'realcaptcha') {
                    $('#captchbox').hide();
                }

            });

            $('#sendsms').click(function() {
                var submit_logregtype = $('.layui-show').attr('submit_logregtype');

                if (submit_logregtype == 1 && $('#username').val() == '') {
                    toastr_error('请填写账户');
                    return;
                }

                if (submit_logregtype == 2 && $('#phone').val() == '') {
                    toastr_error('请填写手机号');
                    return;
                }

                if ($('#captcha').val() == '') {
                    toastr_error('请填写验证码');
                    return;
                }


                $.ajax({
                    url: '/uc/Logreg/loginSendsms', //请求路径
                    type: "POST", //请求方式
                    data: {
                        username: $('#username').val(),
                        phone: $('#phone').val(),
                        captcha: $('#captcha').val(),
                        submit_logregtype: submit_logregtype,
                        captchatype: $('#captchatype').val()
                    }, // 默认写法
                    success: function(data) {
                        if (data.code == 0) {
                            countdown('showcaptch', 60);
                            $('#captchbox').hide();
                        } else {
                            layer.msg(data.message);
                            $('#captchaimg').attr('src', '/uc/Logreg/captcha?width=' + $('#captchaimg').attr('width') + '&height=' + $('#captchaimg').attr('height') + '&t=' + Math.random());
                        }
                    },
                    error: function() {

                    },

                });
            });


            //按钮倒计时
            function countdown(btn, seconds) {
                $('#' + btn).attr('disabled', true); // 禁用按钮
                $('#' + btn).text('已发送(' + seconds + ')'); // 按钮显示倒计时时间

                if (seconds > 0) {
                    seconds--; // 更新剩余秒数
                    setTimeout(function() {
                        countdown(btn, seconds); // 递归调用自己，实现倒计时
                    }, 1000); // 延迟 1 秒执行
                } else {
                    $('#' + btn).attr('disabled', false); // 恢复按钮可用
                    $('#' + btn).text('重新获取');
                }
            }


            form.on('submit(login_submit)', function(data) {
                $.ajax({
                    url: '/uc/Logreg/index', //请求路径
                    type: "POST", //请求方式
                    data: data.field, // 默认写法
                    success: function(data) {
                        if (data.code == 0) {

                            window.location.href = data.data.tourl;
                        } else {

                            toastr_error(data.message);
                        }
                    },
                    error: function() {

                    },

                });
            });
        });
    </script>
</body>

</html>